﻿using Hx.ADSyncPlatform.ActiveDirectory.Attributes;
using System.Linq;

namespace Hx.ADSyncPlatform.ActiveDirectory.Model
{
    /// <summary>
    /// 组织
    /// </summary>
    public class Organization : DirectoryObject
    {
        /// <summary>
        /// 组织名称
        /// </summary>
        private string ou;
        [RequiredForCreate]
        public string Ou
        {
            get
            {
                return ou;
            }
            set
            {
                ou = value;
                AssignedAttributes.Add(nameof(Ou));
            }
        }

        /// <summary>
        /// 国家
        /// </summary>
        private string c;
        [ReadOnlyCustom]
        public string C
        {
            get
            {
                return c;
            }
            set
            {
                c = value;
                AssignedAttributes.Add(nameof(C));
            }
        }

        /// <summary>
        /// 城市
        /// </summary>
        private int countryCode;
        public int CountryCode
        {
            get
            {
                return countryCode;
            }
            set
            {
                countryCode = value;
                AssignedAttributes.Add(nameof(CountryCode));
            }
        }

        /// <summary>
        /// 市县
        /// </summary>
        private string l;
        public string L
        {
            get
            {
                return l;
            }
            set
            {
                l = value;
                AssignedAttributes.Add(nameof(L));
            }
        }

        /// <summary>
        /// 地址
        /// </summary>
        private string postalAddress;
        public string PostalAddress
        {
            get
            {
                return postalAddress;
            }
            set
            {
                postalAddress = value;
                AssignedAttributes.Add(nameof(PostalAddress));
            }
        }

        /// <summary>
        /// 邮政编码
        /// </summary>
        private string postalCode;
        public string PostalCode
        {
            get
            {
                return postalCode;
            }
            set
            {
                postalCode = value;
                AssignedAttributes.Add(nameof(postalCode));
            }
        }

        /// <summary>
        /// 是否在全球结构地址簿中隐藏
        /// </summary>
        private bool showInAddressBook;
        [ReadOnlyCustom]
        public bool ShowInAddressBook
        {
            get
            {
                return showInAddressBook;
            }
            set
            {
                showInAddressBook = value;
                AssignedAttributes.Add(nameof(ShowInAddressBook));
            }
        }

        /// <summary>
        /// 省/自治区
        /// </summary>
        private string st;
        public string St
        {
            get
            {
                return st;
            }
            set
            {
                st = value;
                AssignedAttributes.Add(nameof(St));
            }
        }

        /// <summary>
        /// 街道
        /// </summary>
        private string street;
        public string Street
        {
            get
            {
                return street;
            }
            set
            {
                street = value;
                AssignedAttributes.Add(nameof(Street));
            }
        }

        /// <summary>
        /// 手机号码
        /// </summary>
        private string telephoneNumber;
        public string TelephoneNumber
        {
            get
            {
                return telephoneNumber;
            }
            set
            {
                telephoneNumber = value;
                AssignedAttributes.Add(nameof(TelephoneNumber));
            }
        }

        /// <summary>
        /// 传真号码
        /// </summary>
        private string telexNumber;
        public string TelexNumber
        {
            get
            {
                return telexNumber;
            }
            set
            {
                telexNumber = value;
                AssignedAttributes.Add(nameof(TelexNumber));
            }
        }

        /// <summary>
        /// 传真
        /// </summary>
        private string facsimileTelephoneNumber;
        public string FacsimileTelephoneNumber
        {
            get
            {
                return facsimileTelephoneNumber;
            }
            set
            {
                facsimileTelephoneNumber = value;
                AssignedAttributes.Add(nameof(FacsimileTelephoneNumber));
            }
        }

        private string managedBy;

        /// <summary>
        /// 管理者
        /// </summary>
        [ReadOnlyCustom]
        public string ManagedBy
        {
            get
            {
                return managedBy;
            }
            set
            {
                managedBy = value;
                AssignedAttributes.Add(nameof(ManagedBy));
            }
        }

        private string streetAddress;
        /// <summary>
        /// 街道
        /// </summary>
        [ReadOnlyCustom]
        public string StreetAddress
        {
            get
            {
                return streetAddress;
            }
            set
            {
                streetAddress = value;
                AssignedAttributes.Add(nameof(StreetAddress));
            }
        }

        public string ParentOU
        {
            get
            {
                if (!string.IsNullOrEmpty(this.DistinguishedName) && this.DistinguishedName.Contains(","))
                {
                    string[] distinguishedNameArray = this.DistinguishedName.Split(",");
                    return string.Join(",", distinguishedNameArray.Skip(2));

                }
                return "";
            }
        }
    }
}
